import radius as radius

@description('Specifies the environment for resources.')
param environment string

resource app 'Applications.Core/applications@2023-10-01-preview' = {
  name: 'casdoor'
  properties: {
    environment: environment
  }
}
resource casdoor 'Applications.Core/containers@2023-10-01-preview' = {
  name: 'casdoor'
  properties: {
    application: app.id
    container: {
      image: 'casbin/casdoor:latest'
      env: {
        FOO: 'bar'
      }
      ports: {
        web: {
          containerPort: 8000
        }
      }
    }
    connections: {
      mysql: {
        source: mysql.id
      }
      // backend: {
      //   source: 'http://${backend.name}:80'
      // }
    }
  }
}


resource mysql 'Applications.Datastores/mysql@2023-10-01-preview' = {
  name: 'mysql'
  properties: {
    environment: environment
    application: app.id
  }
}

resource gateway 'Applications.Core/gateways@2023-10-01-preview' = {
  name: 'gateway'
  properties: {
    application: app.id
    hostname: {
      // Omitting hostname properties results in gatewayname.appname.PUBLIC_HOSTNAME_OR_IP.nip.io
      
      // Results in prefix.appname.PUBLIC_HOSTNAME_OR_IP.nip.io
      prefix: 'prefix'
      // Alternately you can specify your own hostname that you've configured externally
      fullyQualifiedHostname: 'casdoor.youling.io'
    }
    routes: [
      {
        path: '/'
        destination: 'http://${casdoor.name}:8000'
      }
      // {
      //   path: '/backend'
      //   destination: 'http://${backend.name}:8080'
      // }
    ]

  }
}
